package com.lkd.controller;

import com.lkd.dto.PartnerPageDto;
import com.lkd.entity.Partner;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.PartnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/user-service/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;
    //新增合作商
    @PostMapping
    public Result save(@RequestBody Partner partner){
        Boolean result=partnerService.save(partner);
        return Result.success(result);
    }

    //合作商搜索
    @GetMapping("/search")
    public Result getPage(PartnerPageDto partnerPageDto){
        PageBean pageBean=partnerService.getPage(partnerPageDto);
        return Result.success(pageBean);
    }
    //获取合作商详情
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Partner partner=partnerService.getById(id);
        return Result.success(partner);
    }

    //根据合作商ID修改合作商
    @PutMapping
    public Result update(@RequestBody Partner partner){
        Boolean result=partnerService.update(partner);
        return Result.success(result);
    }

    //删除合作商
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        Boolean result=partnerService.deleteById(id);
        return Result.success(result);
    }

    //获取合作商数量
    @GetMapping("/count")
    public Result getPartnerCount() {
        return Result.success(partnerService.count());
    }
}
